/**
 * @author nada
 * 
 * --- just a stub ---
 * has to be rewritten before being really prductive
 * 
 */
 
import ch.sfug.utils.Delegate;

class ch.sfug.system.CustomContextMenu
{
	
	private var ccm:ContextMenu;

	/**
	 * constructor
	 */
	public function CustomContextMenu(target:MovieClip)
	{
		trace("CustomContextMenu Class <- alpha test release. not productive!!!");
		if(target == undefined) target = _root;	//NOT NICE
		
		ccm = new ContextMenu();
		ccm.hideBuiltInItems();
		target.menu = ccm;
	}
	
	public function addEntry(entry:String, handler:Function, seperatorBefore:Boolean):Void 
	{
		ccm.customItems.push(new ContextMenuItem(entry, handler, seperatorBefore));
	}
	
	public function removeEntry(entry:String):Void
	{
		ccm.customItems.splice(getEntryIndex(entry), 1);
	}
	
	public function showEntry(entry:String):Void
	{
		ccm.customItems[getEntryIndex(entry)].visible = true;
	}
	
	public function hideEntry(entry:String):Void
	{
		ccm.customItems[getEntryIndex(entry)].visible = false;
	}
	
	public function enableEntry(entry:String):Void
	{
		ccm.customItems[getEntryIndex(entry)].enabled = true;
	}
	
	public function disableEntry(entry:String):Void
	{
		ccm.customItems[getEntryIndex(entry)].enabled = false;
	}
	
	public function addSeparator(entry:String):Void
	{
		ccm.customItems[getEntryIndex(entry)].separatorBefore = true;
	}
	
	public function removeSeparator(entry:String):Void
	{
		ccm.customItems[getEntryIndex(entry)].separatorBefore = false;
	}
	
	//---
	
	private function getEntryIndex(entry:String):Number
	{
		var entryIndex:Number = null;
		for(var i:Number = 0; ccm.customItems.length; i++)
		{
			if(ccm.customItems[i].caption == entry) 
			{
				entryIndex = i;
				break;
			}	
		}
		return entryIndex;
	}
	
}